import { Component } from '@angular/core';
import { HttpClient } from '@angular/common/http';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'app';

  constructor(private http:HttpClient){}
 host='http://192.168.3.4';
 helloUrl='/public/hello';
 stringUrl='/public/getTestString';
 getObjectUrl='/public/getObject';
 postObjectUrl='/public/receiveAnObject';
 signupUrl="/users/signup";
 username:string;
 password='';
 user={
'username':'',
'password':''
 }

connectTest(){
  console.log('连接测试');


  this.http.get(this.host+this.stringUrl)
  .subscribe((data)=>{
    console.log(data);
  },(err)=>{
    console.log('error ');
    console.log(err);
  }

)



}


postObjectTest(){
  console.log('对象提交测试');
this.http.post(this.host+this.postObjectUrl,{
  'id':'1',
  'username':'tuname',
  'password':'tpass'
})
.subscribe((res)=>{
  console.log(res);
},(err)=>{
  console.log("error Occured");
  console.log(err);
})

}


postAnFormTest(){
  //console.log(this.username+"--"+this.password);

  this.http.post(this.host+this.postObjectUrl,this.user)
    .subscribe((res)=>{
      console.log(res);
    },(err)=>{
      console.log('error Occured');
      console.log(err);
    })
}


signup(){
  this.http.post(this.host+this.signupUrl,this.user)
  .subscribe((res)=>{
    console.log(res);

  },(err)=>{
    console.log('error Occured');
    console.log(err);
  })
}


login(){
  this.http.post(this.host+'/login',this.user)
  .subscribe((res)=>{
    console.log('登陆成功');
    

  },(err)=>{
    console.log('error Occured');
    console.log(err);
  })
}




}
